﻿using System;
using UnityEngine;
using UnityEngine.UI;
using static System.Net.Mime.MediaTypeNames;

public class PhotosData
{
    public string icon;
    public string tex1;
    public string tex2;
    public string tex3;
    public string tex4;
    public string tex5;
    public string tex6;
    public Tex iconTex;
    public Tex tex1Tex;
    public Tex tex2Tex;
    public Tex tex3Tex;
    public Tex tex4Tex;
    public Tex tex5Tex;
    public Tex tex6Tex;
    public PhotosData(UserInfo userInfo)
    {
        this.icon = userInfo.icon;
        this.tex1 = userInfo.tex1;
        this.tex2 = userInfo.tex2;
        this.tex3 = userInfo.tex3;
        this.tex4 = userInfo.tex4;
        this.tex5 = userInfo.tex5;
        this.tex6 = userInfo.tex6;
    }
}

public class EditPhotosWidget : MonoBehaviour
{
    public EditPhotoItem tex1;
    public EditPhotoItem tex2;
    public EditPhotoItem tex3;
    public EditPhotoItem tex4;
    public EditPhotoItem tex5;
    public EditPhotoItem tex6;

    PhotosData m_photosData;
    Action<PhotosData> m_refreshPhotosWidget;

    public void Init(PhotosData photosData, Action<PhotosData> refreshPhotosWidget)
    {
        m_photosData = photosData;
        m_refreshPhotosWidget = refreshPhotosWidget;

        tex1.Init(TexId.tex1, photosData.tex1, OnTexLoaded,OnRemoveImg);
        tex2.Init(TexId.tex2, photosData.tex2, OnTexLoaded,OnRemoveImg);
        tex3.Init(TexId.tex3, photosData.tex3, OnTexLoaded,OnRemoveImg);
        tex4.Init(TexId.tex4, photosData.tex4, OnTexLoaded,OnRemoveImg);
        tex5.Init(TexId.tex5, photosData.tex5, OnTexLoaded,OnRemoveImg);
        tex6.Init(TexId.tex6, photosData.tex6, OnTexLoaded,OnRemoveImg);
    }

    private void OnTexLoaded(int id, Tex tex)
    {
        if (id == TexId.tex1)
        {
            m_photosData.tex1Tex = tex;
        }
        else if (id == TexId.tex2)
        {
            m_photosData.tex2Tex = tex;
        }
        else if (id == TexId.tex3)
        {
            m_photosData.tex3Tex = tex;
        }
        else if (id == TexId.tex4)
        {
            m_photosData.tex4Tex = tex;
        }
        else if (id == TexId.tex5)
        {
            m_photosData.tex5Tex = tex;
        }
        else if (id == TexId.tex6)
        {
            m_photosData.tex6Tex = tex;
        }

        m_refreshPhotosWidget?.Invoke(m_photosData);
    }

    public void OnRemoveImg(int id)
    {
        if (id == TexId.tex1)
        {
            m_photosData.tex1 = null;
        }
        else if (id == TexId.tex2)
        {
            m_photosData.tex2 = null;
        }
        else if (id == TexId.tex3)
        {
            m_photosData.tex3 = null;
        }
        else if (id == TexId.tex4)
        {
            m_photosData.tex4 = null;
        }
        else if (id == TexId.tex5)
        {
            m_photosData.tex5 = null;
        }
        else if (id == TexId.tex6)
        {
            m_photosData.tex6 = null;
        }

        m_refreshPhotosWidget?.Invoke(m_photosData);
    }


}
